package com.toomoss.USB2XXX;

import java.util.Arrays;
import java.util.List;

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Structure;

public interface USB2K extends Library {
    USB2K INSTANCE  = (USB2K) Native.loadLibrary("USB2XXX",USB2K.class);
	//定义K数据结构体
	public class K_MSG  extends Structure{
		
	    public static class ByReference extends K_MSG implements Structure.ByReference {}  
	    public static class ByValue extends K_MSG implements Structure.ByValue {}  
	  
		@Override
		protected List getFieldOrder() {
			// TODO Auto-generated method stub
			return Arrays.asList(new String[]{"Fmt", "TgtAddr", "SrcAddr", "Len","SId","Data","CS"});
		}
	    
		public byte   Fmt;
		public byte   TgtAddr;
		public byte   SrcAddr;
		public byte   Len;
		public byte   SId;
		public byte[] Data = new byte[254];
		public byte   CS;
	}
	//定义函数返回错误代码
	public static int K_SUCCESS                  = (0);   //函数执行成功
	public static int K_ERR_NOT_SUPPORT          = (-1);  //适配器不支持该函数
	public static int K_ERR_USB_WRITE_FAIL       = (-2);  //USB写数据失败
	public static int K_ERR_USB_READ_FAIL        = (-3);  //USB读数据失败
	public static int K_ERR_CMD_FAIL             = (-4);  //命令执行失败
	public static int K_ERR_SERVER_NO_RESPONSE   = (-5);  //ECU无响应
	public static int K_ERR_RESPONSE             = (-6);  //ECU响应数据错误
	public static int K_ERR_SEND_DATA            = (-7);  //数据发送出错
	public static int K_ERR_CHECK_ERROR          = (-8);  //数据发送出错
    //USB2K相关函数定义
    int K_Init(int DevHandle, byte Channel,int BaudRate);
    int K_5BaudInit(int DevHandle, byte Channel,byte Addr,byte[] pKB1,byte[] pKB2);
    int K_FastInit(int DevHandle, byte Channel,K_MSG[] pRequest,K_MSG[] pResponse,byte InterByteTimeMs);
    int K_Request(int DevHandle, byte Channel,K_MSG[] pRequest,K_MSG[] pResponse,byte InterByteTimeMs,int ResponseTimeOutMs);
}
